<template>
  <div class="container">
    <h2>高校毕业生专区</h2>
    <div v-if='data&&data.length'>
      <div class="all">
        <el-checkbox v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
        <!-- <el-button class="downLoad">下载简历</el-button> -->
        <el-button class="Collection" @click="collection">收藏简历</el-button>
      </div>
      <div v-for="item in data" :key="item.id" class="talentList">
        <div class="talentInfo">
          <el-checkbox v-model="item.choose" @change="handleCheckChange(item.choose,item.id)"></el-checkbox>
          <img :class="{girl:item.sex!==1}" :src="item.photoAuditStatus===1?item.photo:''" alt />
          <div class="info">
            <div  @click="()=>{toResume(item.id,item.userId)}" class="hand">
              <h4>{{item.name}}</h4>
              <p>
                {{item.sex==1?"男":'女'}}
                <i></i>
                {{item.age}}岁
                <i></i>
                {{item.currentResidenceText?item.currentResidenceText:'现住址 : 未填写'}}
                <i></i>
                {{item.educationText?item.educationText:'无'}}
              </p>
            </div>
            <p>
              <span
                v-if="item.resumeEducationOutVo">{{item.resumeEducationOutVo[0].startTime?item.resumeEducationOutVo[0].startTime.slice(0,7).replace('-','.'):''}}-{{item.resumeEducationOutVo[0].endTime?item.resumeEducationOutVo[0].endTime.slice(0,7).replace('-','.'):''}}</span>
              <span v-else>学历暂无</span>
              <span>{{item.resumeEducationOutVo?item.resumeEducationOutVo[0].school:''}}</span>
              <span>{{item.resumeEducationOutVo?item.resumeEducationOutVo[0].major:''}}</span>
            </p>
          </div>
        </div>
        <ul class="workExp" v-if="item.resumeWorkOutVo">
          <li>
            <p>
              {{item.resumeWorkOutVo[0].startTime?item.resumeWorkOutVo[0].startTime.slice(0,7).replace('-','.'):''}} -
              {{item.resumeWorkOutVo[0].endTime?item.resumeWorkOutVo[0].endTime.slice(0,7).replace('-','.'):'至今'}}</p>
            <p>
              {{item.resumeWorkOutVo[0].company}}
              <i></i>
              {{item.resumeWorkOutVo[0].job}}
            </p>
          </li>
          <li v-if="item.resumeWorkOutVo[1]">
            <p>
              {{item.resumeWorkOutVo[1].startTime?item.resumeWorkOutVo[1].startTime.slice(0,7).replace('-','.'):''}} -
              {{item.resumeWorkOutVo[1].endTime?item.resumeWorkOutVo[1].endTime.slice(0,7).replace('-','.'):'至今'}}
              <i></i>
            </p>
            <p>
              {{item.resumeWorkOutVo[1].company}}
              <i></i>
              {{item.resumeWorkOutVo[1].job}}
            </p>
          </li>
        </ul>
        <div class="workExp" v-else>工作经历未填写</div>
        <div class="refreshTime">
          <p>更新时间：{{item.refreshTime?item.refreshTime.slice(0,10):'暂无更新时间'}}</p>
        </div>
      </div>
    </div>
    <div v-else class="noData">
      暂无数据
    </div>
    <div class="page">
      <el-pagination background @current-change="handleCurrentChange" :current-page="page" layout="prev, pager, next"
        :total="total"></el-pagination>
    </div>
  </div>
</template>

<script>
import { graduatesResume } from '../../../api/talentPool'
import { resumeCollect } from '../../../api/resume'
export default {
  name: 'university',
  data () {
    return {
      page: 1,
      size: 10,
      total: 0,
      data: [],
      checkAll: false,
      selection: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    // 全选
    handleCheckAllChange (val) {
      this.data.forEach(item => {
        item.choose = val;
      });
      this.selection = this.data.filter(item => {
        return item.choose
      });
      console.log(val);
      console.log(this.selection);
    },
    // 单选
    handleCheckChange (value, val) {
      this.selection = this.data.filter(item => {
        return item.choose
      });
      this.checkAll = this.data.every(item => item.choose);
      console.log(value, val);
      console.log(this.selection);
    },
    // 收藏
    collection () {
      if (this.selection.length === 0) {
        this.$message.error('请选择需要收藏的简历!')
        return
      }
      let query = this.selection.map(item => item.id)
      resumeCollect(query).then(res => {
        if (res.success) {
          this.$message.success('收藏成功');
          this.getList();
        } else {
          this.$message.error(`${res.msg}`)
        }
      })
    },
    // 跳转简历详情
    toResume (id, userId) {
      const { href } = this.$router.resolve({
        path: "/resumeManage",
        query: { id, userId, path: 'talent' }
      });
      window.open(href, '_blank');
    },
    // 获取高校列表
    getList () {
      let query = {
        page: this.page,
        size: this.size
      };
      graduatesResume(query).then(res => {
        if (res.success) {
          if (res.data.records) {
            this.total = res.data.total;
            this.data = res.data.records.map(item => {
              item.choose = false;
              return item;
            });
            console.log(this.data);
          } else {
            this.data = [];
            this.total = 0;
          }
        } else {
          this.$message.error(res.msg)
        }
        this.selection = [];
        console.log(this.selection);

        this.checkAll = false;
      })
    },
    handleCurrentChange (val) {
      this.page = val;
      this.getList();
    }
  }
}
</script>

<style lang="css" scoped>
.container {
    padding: 0 0 20px;
    background: rgba(246, 246, 248, 1);
    border: none;
}
h2 {
    height: 60px;
    line-height: 60px;
    padding-left: 35px;
    background: #ffffff;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    color: rgba(34, 34, 34, 1);
    opacity: 1;
}
.all {
    padding-left: 44px;
    margin: 16px 0;
    width: 1200px;
    height: 50px;
    line-height: 50px;
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
}
.all .downLoad {
    margin-left: 32px;
    width: 94px;
    height: 24px;
    line-height: 0;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    background: rgba(24, 147, 252, 1);
    opacity: 1;
}
.hand{
  color: #1893fc;
  cursor: pointer;
}
.all .Collection {
    line-height: 0;
    width: 94px;
    height: 24px;
    background: rgba(255, 255, 255, 1);
    border: 1px solid rgba(24, 147, 252, 1);
    opacity: 1;
    margin-left: 16px;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(24, 147, 252, 1);
}
.talentList {
    margin-bottom: 12px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    padding: 23px 44px;
    width: 1200px;
    /* height: 134px; */
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.talentList .talentInfo {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.talentList .talentInfo img {
    width: 72px;
    height: 72px;
    margin: 0 32px;
    background: url('../../../assets/img/logo.png') no-repeat;
    background-size: 100% 100%;
    border-radius: 50%;
    opacity: 1;
}
.talentList .talentInfo img.girl {
    background: url('../../../assets/img/logoG.png') no-repeat;
    background-size: 100% 100%;
}
.talentList .talentInfo .info {
    width: 340px;
}
.talentList .talentInfo .info h4 {
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 22px;
    /* color: rgba(34, 34, 34, 1); */
    opacity: 1;
    cursor: pointer;
}
.talentList .talentInfo .info p {
    margin-top: 8px;
    /* height: 20px; */
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    /* color: rgba(85, 85, 85, 1); */
    opacity: 1;
}
.talentList .talentInfo .info p span {
    display: inline-block;
    margin-right: 16px;
}
.noData {
    width: 100%;
    height: 100px;
    line-height: 100px;
    text-align: center;
    background: #fff;
    font-size: 20px;
    color: #606266;
}
.talentList i {
    vertical-align: top;
    display: inline-block;
    margin: 3px 10px 0;
    width: 0px;
    height: 14px;
    border: 0.5px solid #1893fc;
    opacity: 1;
}
.talentList .workExp i {
    border: 0.5px solid rgba(112, 112, 112, 1);
}
.talentList .workExp {
    width: 400px;
    color: #1893fc;
}
.talentList .workExp li {
    margin-top: 8px;
}
.talentList .workExp li p:nth-child(1)::before {
    vertical-align: middle;
    display: inline-block;
    content: '';
    width: 4px;
    height: 4px;
    margin: 0 4px 0 -14px;
    background: #1893fc;
    border-radius: 50%;
}
.talentList .workExp li p:nth-child(1) {
    margin-bottom: 4px;
    height: 22px;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 22px;
    color: rgba(51, 51, 51, 1);
    opacity: 1;
}
.talentList .workExp li p:nth-child(2) {
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(85, 85, 85, 1);
    overflow: hidden;
    white-space: nowrap;
    opacity: 1;
}
.talentList .refreshTime {
    /* height: 80px; */
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 40px;
    color: rgba(85, 85, 85, 1);
    opacity: 1;
}
.page {
    text-align: center;
    margin-bottom: 30px;
    background: #fff;
    padding: 20px 0;
}
</style>